<?php

namespace App\LayAdmin\Controllers;

use App\Exceptions\ExceptionApi;
use App\LayAdmin\Components\Lay;
use App\Services\Response as ApiResponse;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Http\Response;

class BaseController extends Controller
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $lay;

    public function __construct()
    {
        $this->lay = Lay::getInstance()->setTitle('抖个球');
        $this->lay->getTemplate()->setViewPath(dirname(__DIR__)."/views");
        $this->lay->setHomeUrl("/admin/videos");
        $this->lay->setLogoutUrl("/logout");
        $menu = $this->lay->getMenu();
        $menu->setMenuByFile(dirname(__DIR__)."/menu.php");
        $menu->setLogoTitle('抖个球');
    }

    protected function successApi($msg='操作成功',$data=null):Response{
        return ApiResponse::apiSuccess($data, $msg);
    }

    protected function errorOptFail($msg='操作失败', $code=500){
        throw new ExceptionApi($msg, $code);
    }

    protected function errorRequest($msg='请求错误', $code=400){
        throw new ExceptionApi($msg, $code);
    }

}
